package stocks.server;

enum mode {
	BUY,
	SELL
}

/**
 * This class represents one stock to be bought or sold
 * @author Brendan
 */
public class QueuedStock implements Comparable,Cloneable {
	mode theMode;
	int price;
	String name;
	String owner;
	int quantity;
	CallBack ownerCallback;
	
	public int getQuantity() {
		return quantity;
	}

	public void setQuantity(int quantity) {
		this.quantity = quantity;
	}

	QueuedStock(String name,int price,String owner,mode theMode,int quantity,CallBack ownerCallback) {
		this.theMode = theMode;
		this.owner = owner;
		this.price = price;
		this.name = name;
		this.quantity = quantity;
		this.ownerCallback = ownerCallback;
	}
	
	public CallBack getOwnerCallback() {
		return ownerCallback;
	}

	public void setOwnerCallback(CallBack ownerCallback) {
		this.ownerCallback = ownerCallback;
	}

	public mode getTheMode() {
		return theMode;
	}

	public void setTheMode(mode theMode) {
		this.theMode = theMode;
	}

	public int getPrice() {
		return price;
	}

	public void setPrice(int price) {
		this.price = price;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getOwner() {
		return owner;
	}

	public void setOwner(String owner) {
		this.owner = owner;
	}

	public int compareTo(Object other) {
		QueuedStock otherStock = (QueuedStock) other;
		if(theMode == mode.SELL) {
			if(this.getPrice() < otherStock.getPrice()) {
				return -1;
			} else if (this.getPrice() > otherStock.getPrice()) {
				return 1;
			} else {
				return 0;
			}
		} else if(theMode == mode.BUY) {
			if(this.getPrice() < otherStock.getPrice()) {
				return 1;
			} else if (this.getPrice() > otherStock.getPrice()) {
				return -1;
			} else {
				return 0;
			}
		}
		
		return 0;
	}
	
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }

}
